package Basics;

import java.util.Vector;

public class Body 
{
	
	Vector<Atom> atoms = new Vector<Atom>();
	
	int derivedInlevel = 0;
	
	Rule ruleUsed = null;
	
	
	public Body () {}
	
	
	public Body (Vector<Atom> iatoms) 
	{
		this.atoms = iatoms;
	}
	
	
	public Body (Atom ... iatoms) 
	{
		for (Atom atom : iatoms) 
		{
			this.atoms.add(atom);
		}
	}


	/*************************************************************************************************************/
	/** Title: Body																				
	/** Description: Copy constructor				
	/*************************************************************************************************************/
	
	public Body (Body other)
	{
		for (Atom atom : other.getAtoms()) 
		{
			this.atoms.add(atom);
		}
		
		this.derivedInlevel = other.getDerivedInlevel();
		this.ruleUsed = other.getRuleUsed();
	}

	
	
	public int getDerivedInlevel() 
	{
		return derivedInlevel;
	}


	public void setDerivedInlevel(int derivedInlevel) 
	{
		this.derivedInlevel = derivedInlevel;
	}


	public Vector<Atom> getAtoms() 
	{
		return atoms;
	}


	public void setAtoms(Vector<Atom> atoms) 
	{
		this.atoms = atoms;
	}


	public Rule getRuleUsed() 
	{
		return ruleUsed;
	}


	public void setRuleUsed(Rule ruleUsed) 
	{
		this.ruleUsed = ruleUsed;
	}
	
	
	
	
	/*************************************************************************************************************/
	/** Title: IdenticalAtoms																	
	/** Description: Returns true iff this has the same atoms as other  						
	/*************************************************************************************************************/
	
	public boolean IdenticalAtoms (Body other)
	{
		boolean retVal = true;
		for (int i = 0; i < this.atoms.size(); i++) 
		{
			if (false == this.atoms.elementAt(i).equals(other.getAtoms().elementAt(i)))
			{
				retVal = false;
				break;
			}
		}
		
		return retVal;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((atoms == null) ? 0 : atoms.hashCode());
		/*result = prime * result + derivedInlevel;
		result = prime * result
				+ ((ruleUsed == null) ? 0 : ruleUsed.hashCode());*/
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Body other = (Body) obj;
		if (atoms == null) {
			if (other.atoms != null)
				return false;
		} else if (!atoms.equals(other.atoms))
			return false;
		/*if (derivedInlevel != other.derivedInlevel)
			return false;*/
		/*if (ruleUsed == null) {
			if (other.ruleUsed != null)
				return false;
		} else if (!ruleUsed.equals(other.ruleUsed))
			return false;*/
		return true;
	}


}
